Geospatial Querying and Prompts
Prerequisites
These examples require configuration on the part of the Qarbine Administrator to access the supporting services. The Qarbine Administrator must define a Mapbox token to use the map custom cell. Instructions to do this are within the Tools;Administration Tool area of http://doc.qarbine.com.
Using Lookup Geo Coordinates
Sample Prompt
In some cases your application has access to geo coordinate information to leverage within a Qarbine analysis. The following discusses the details behind the following prompt dialog.
This example is in the catalog as “example/Qarbine techniques/Geospatial/Prompt for city and airport type”. The prompt has 3 elements.
The city list widget is populated using the following formula
retrieveData("Sample Data Service", "db.cityCoords.find({}).sort({label:1})")
The “Sample Data Service” has a database “q_sample” with the following collection.
The drop down widget is populated by this formula
listFromField(retrieveData("Sample Data Service",
"db.airports.aggregate( [ {$group:{_id: '$type'} }, {$sort:{ '_id':1 } } ]) "), "_id")
it also has this setting.
WHen testing this prompt notice the output is a city object and a type string. The former has label, lat(itude), and long(itude) fields.
Consuming Data Source
A data source component can use these variables to define its query specification as shown below.
db.airports.find( {
[! if (@type= "_All_", null, unquote(" type: @type," ) ) !]
loc : {$near : {$geometry : {type : "Point" ,
coordinates : [[!@city.long!],[!@city.lat!]] }, $maxDistance : 40000} }},
{name : 1, code : 1, loc : 1, _id : 0, type:1} )
The “[! if(...) !]” snippet is preprocessed by Qarbine. When “All” is chosen in the prompt the final query looks like this
db.airports.find( {
loc : {$near : …} },
{name : 1, code : 1, loc : 1, _id : 0, type:1} )
When a some other type is chosen the final query looks like this
db.airports.find( {
type: @type,
loc : {$near : …} },
{name : 1, code : 1, loc : 1, _id : 0, type:1} )
This example uses the MongoDB query language. The approach applies to other data services.
The example is in the catalog as “example/Qarbine techniques/Geospatial/Airports near @city of type @type”.
Consuming Template
Sample output from the following template is shown below.
Shown below is the “Map View Button” tooltip in the result.
Clicking it opens a new tab on the associated geo coordinate.
The template’s properties reference the data source.
That data source references the aforementioned prompt. The general shape of the data source answer set elements is shown on the right side of the Template Designer.
The general template layout is shown below.
There are 2 custom cells being used. On the body line is a “Map View Button” that when clicked opens Google maps at a particular geo coordinate. On the group summary is a map custom cell.
The “Map View Button” body cell formula is
pt = pointFromGeoJsonHolder(#loc, #name)
This creates a point object with long(itude) and lat(itude) fields along with a label.
The airport name follows along with the geo coordinates. To display the longitude and latitude we use the formula pattern of
= format(@pt.long, "Number", "#0.00")
Finally we include the type of airport to the right.
The map is on the group summary line. It uses the following formula to collect the markers to display on the map.
Running the template displays the prompt.
The prompt runtime values flow into the data source query specification to form the final query. The data request is made and the answer set consumed based on the template definition. The results are then shown to the user.
This component is in the catalog as “example/Qarbine techniques/Geospatial/Airport detail map”.
Using Geospatial Map Prompt
Sample Prompt
In some cases specific geo coordinates are less ideal and a map metaphor is preferred. A Qarbine prompt can include a “Map” widget to obtain this information. A prompt with just a sigle prompt element is shown below.
Running the Prompt
Running it displays the following.
Clicking opens up another dialog.
You can interact with this dialog using panning, zooming, and entering a place name.
The place name lookup requires the Qarbine administrator to configure the geospatial lookup settings. This is described in the Tool;Administrator section of http://doc.qarbine.com.
Once the circular area is set, click
The values are filled into the regular prompt dialog.
To continue click
Result Variables
The resulting variables are shown below.
This component is in the catalog as “example/Qarbine techniques/Geospatial/Prompt for geographic location”.
Defining a Geo Aware Data Source
A data source component can use these variables to define its query specification as shown below.
db.airports.find( {
loc : {$near : {$geometry : {type : "Point" ,
coordinates : [ [!@where.longitude!],[!@where.latitude!] ] },
$maxDistance : @radius} }},
)
This example uses the MongoDB query language. The approach applies to other data services.
Associate the prompt to the data source.
Run the data source which will display the prompt.
Click to open the map area dialog.
Close the dialog by clicking
The values are filled in
Accept the prompt values by clicking
The variables are used by the query specification and the query is run.
This component is in the catalog as “example/Qarbine techniques/Geospatial/Airports near @where”.